<?php
/**
 * Created by PhpStorm.
 * User: lihao
 * Date: 2017/7/25
 * Time: 下午3:47
 */

class User_model extends CI_Model {
    public function __construct() {
        parent::__construct();
    }

    public function create($data) {
        $re = $this->db->insert('users', $data);
        // true false
        return $re;
    }

    public function search($username = null, $uid = null, $limit = null, $offset = 0) { //offset 偏移  limit 数量
        $this->db->select('*');
        $this->db->from('users');
        if ($username != null) {
            $this->db->where('user', $username);
        } else if ($uid != null) {
            $this->db->where('uid', $uid);
        }
        if ($limit != null) {
            $this->db->limit($limit, $offset);
        }
        $re = $this->db->get()->result_array();
        //array()
        return $re;
    }

    public function delete() {

    }

    public function update($uid, $data) {
        $this->db->set($data);
        $this->db->where('uid', $uid);
        $re = $this->db->update('users');
        return $re;
    }
}